package com.emode.base;

import java.lang.reflect.ParameterizedType;
import java.util.List;

import com.emode.entity.Bbsreply;
import com.emode.entity.Bbssection;
import com.emode.entity.Bbstopic;
import com.emode.entity.Bbsusers;
import com.emode.entity.SysGroup;
import com.emode.entity.SysPrivilege;
import com.emode.entity.Syslog;
import com.emode.entity.UserNotifications;
import com.emode.entity.UserSign;
import com.emode.service.imp.IGroupservice;
import com.emode.service.imp.INotification;
import com.emode.service.imp.IPrivilegeService;
import com.emode.service.imp.IReplyService;
import com.emode.service.imp.ISectionService;
import com.emode.service.imp.ISignservice;
import com.emode.service.imp.ITopicService;
import com.emode.service.imp.IUserService;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

public abstract class BaseAction<T> extends ActionSupport implements ModelDriven<T>{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	//service 的映射
	protected IUserService userservice;
	protected ISectionService sectionservice;
	protected ITopicService topicservice;
	protected IReplyService replyservice;
	protected INotification noservice;
	protected IGroupservice groupservice;
	protected IPrivilegeService privilegeservice;
	protected ISignservice signservice;
	//bean的映射
	protected Bbssection section;
	protected Bbstopic topic;
	protected Bbsreply reply;
	protected Bbsusers users,user;
	protected UserNotifications unotice;
	protected SysGroup group;
	protected SysPrivilege privilege;
	protected Syslog log;
	protected UserSign sign;
	
	
	
	//list
	protected List list,list2;
	
	protected String msg;
	protected Pager p = new Pager();
	


	protected T model;
	
	/*
	 * 通过映射得到model的信息类
	 */
	public BaseAction(){
		
		try {
			ParameterizedType pt = (ParameterizedType) this.getClass().getGenericSuperclass();
			Class clazz = (Class) pt.getActualTypeArguments()[0];
			//通过反射生成的model实例
			model = (T) clazz.newInstance();
		} catch (InstantiationException e) {
			throw new RuntimeException(e);
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	//得到当前的用户
	protected Bbsusers getCurrentUser() {
		return (Bbsusers) ActionContext.getContext().getSession().get("user");
	}
	
	@Override
	public T getModel(){
		return model;
	}
	/*********************************get set 方法*********************************************/

	public IUserService getUserservice() {
		return userservice;
	}

	public void setUserservice(IUserService userservice) {
		this.userservice = userservice;
	}

	public ISectionService getSectionservice() {
		return sectionservice;
	}

	public void setSectionservice(ISectionService sectionservice) {
		this.sectionservice = sectionservice;
	}

	public ITopicService getTopicservice() {
		return topicservice;
	}

	public void setTopicservice(ITopicService topicservice) {
		this.topicservice = topicservice;
	}

	public IReplyService getReplyservice() {
		return replyservice;
	}

	public void setReplyservice(IReplyService replyservice) {
		this.replyservice = replyservice;
	}

	public INotification getNoservice() {
		return noservice;
	}

	public void setNoservice(INotification noservice) {
		this.noservice = noservice;
	}
	
	public IGroupservice getGroupservice() {
		return groupservice;
	}

	public void setGroupservice(IGroupservice groupservice) {
		this.groupservice = groupservice;
	}

	public Pager getPage() {
		return p;
	}

	public void setPage(Pager page) {
		this.p = page;
	}
	public Pager getP() {
		return p;
	}

	public void setP(Pager p) {
		this.p = p;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public Bbssection getSection() {
		return section;
	}

	public void setSection(Bbssection section) {
		this.section = section;
	}

	public Bbstopic getTopic() {
		return topic;
	}

	public void setTopic(Bbstopic topic) {
		this.topic = topic;
	}

	public Bbsreply getReply() {
		return reply;
	}

	public void setReply(Bbsreply reply) {
		this.reply = reply;
	}

	public Bbsusers getUsers() {
		return users;
	}

	public void setUsers(Bbsusers users) {
		this.users = users;
	}

	public Bbsusers getUser() {
		return user;
	}

	public void setUser(Bbsusers user) {
		this.user = user;
	}

	public UserNotifications getUnotice() {
		return unotice;
	}

	public void setUnotice(UserNotifications unotice) {
		this.unotice = unotice;
	}

	public List getList() {
		return list;
	}

	public void setList(List list) {
		this.list = list;
	}

	public List getList2() {
		return list2;
	}

	public void setList2(List list2) {
		this.list2 = list2;
	}


	public SysGroup getGroup() {
		return group;
	}

	public void setGroup(SysGroup group) {
		this.group = group;
	}

	public SysPrivilege getPrivilege() {
		return privilege;
	}

	public void setPrivilege(SysPrivilege privilege) {
		this.privilege = privilege;
	}

	public Syslog getLog() {
		return log;
	}

	public void setLog(Syslog log) {
		this.log = log;
	}

	public IPrivilegeService getPrivilegeservice() {
		return privilegeservice;
	}

	public void setPrivilegeservice(IPrivilegeService privilegeservice) {
		this.privilegeservice = privilegeservice;
	}

	public ISignservice getSignservice() {
		return signservice;
	}

	public void setSignservice(ISignservice signservice) {
		this.signservice = signservice;
	}

	public UserSign getSign() {
		return sign;
	}

	public void setSign(UserSign sign) {
		this.sign = sign;
	}
	
	
}
